<template>
  <div class="my">
    <div class="user">
      <div class="btn">
        <van-button round @click="showPopup" type="info">您还没有登录，请登录</van-button>
      </div>
      <div class="login">
        <div class="left">
          <img src="../../assets/logo.png" alt />
        </div>
        <div class="right">
          <van-cell-group>
            <van-cell title="单元格" label="描述信息" />
          </van-cell-group>
        </div>
      </div>

      <van-popup class="model" v-model="show" closeable round>
        <van-form @submit="onSubmit" class="form">
          <van-field
            size="large"
            v-model="username"
            name="username"
            label="用户名"
            placeholder="用户名"
            :rules="[{ required: true, message: '请填写用户名' }]"
          />
          <van-field
            :autosize="true"
            size="large"
            v-model="password"
            type="password"
            name="password"
            label="密码"
            placeholder="密码"
            :rules="[{ required: true, message: '请填写密码' }]"
          />
          <div style="margin: 16px;">
            <van-button round block type="info" native-type="submit">提交</van-button>
          </div>
        </van-form>
      </van-popup>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      show: false,
      username: "",
      password: "",
      user: {},
      userInfo: [
        {
          username: "小花",
          password: "123456",
          role: "会员"
        },
        {
          username: "小红",
          password: "123456",
          role: "会员"
        },
        {
          username: "小绿",
          password: "123456",
          role: "会员"
        }
      ]
    };
  },
  methods: {
    showPopup() {
      this.show = true;
    },
    async onSubmit(values) {
      console.log("submit", values);
      this.userInfo.some(item => {
        if (item.username === values.username) {
          this.$toast.success("登陆成功！");
          this.show = false;
          this.user = item;
        } else {
          return this.$toast.success("登陆失败！");
        }
        return;
      });
    }
  }
};
</script>

<style lang="less" scoped>
.user {
  width: 100%;
  height: 150px;
  background-color: #f40;
}
.model {
  width: 80%;
}
.btn {
  width: 172px;
  margin: 0 auto;
  padding: 30px 0 0;
}
.login {
  display: flex;
  width: 100%;
  img {
    width: 50%;
  }
  .left {
    flex: 30%;
  }
  .right {
    flex: 70%;
  }
}
</style>